import request from '@/config/axios'
import axios from 'axios'
import { getAccessToken } from '@/utils/auth'
import { config } from '@/config/axios/config'

// 审批流程-通用-同意
export const agreeProjectProcess = async (data) => {
  return await request.post({
    url: '/ict/project/approve',
    data
  })
}

// 审批流程-项目定级-建设单位部门经理通过
export const agreeProjectGradingDepartmentManagerProcess = async (data) => {
  return await request.post({
    url: '/ict/grading/approve',
    data
  })
}

// 审批流程-项目定级-建设单位部门经理回退到交付经理
export const refuseGradingProcess = async (data) => {
  return await request.post({
    url: '/ict/grading/return',
    data
  })
}

// 审批流程-团队组建-交付经理通过
export const agreeTeamFormationProcess = async (data) => {
  return await request.post({
    url: '/ict/team/approve',
    data
  })
}

// 审批流程-项目开工-建设单位部门经理通过
export const agreeStartupReportingDepartmentManagerProcess = async (data) => {
  return await request.post({
    url: '/ict/reporting/dept-manager-approve',
    data
  })
}

// 审批流程-项目开工-省端主管通过
export const agreeStartupReportingProjectSupervisorProcess = async (data) => {
  return await request.post({
    url: '/ict/reporting/supervisor-approve',
    data
  })
}

// 审批流程-项目开工-客响主管回退到交付经理
export const refuseStartupReportingProcess = async (data) => {
  return await request.post({
    url: '/ict/reporting/return',
    data
  })
}

// 审批流程-项目定级-建设单位部门经理通过
export const agreeExecuteProgressDepartmentManagerProcess = async (data) => {
  return await request.post({
    url: '/ict/progress/approve',
    data
  })
}

// 审批流程-实施进度-建设单位部门经理回退到交付经理
export const refuseExecuteProgressProcess = async (data) => {
  return await request.post({
    url: '/ict/progress/return',
    data
  })
}

// 审批流程-试运行-建设单位部门经理通过
export const agreeTestRunDepartmentManagerProcess = async (data) => {
  return await request.post({
    url: '/ict/test/approve',
    data
  })
}

// 审批流程-试运行-建设单位部门经理回退到交付经理
export const refuseTestRunProcess = async (data) => {
  return await request.post({
    url: '/ict/test/return',
    data
  })
}

// 审批流程-项目交付-省端主管通过
export const agreeProjectDeliverySupervisorProcess = async (data) => {
  return await request.post({
    url: '/ict/delivery/supervisor-approve',
    data
  })
}

// 审批流程-项目交付-交付经理二次审核通过
export const agreeProjectDeliveryManagerSecondProcess = async (data) => {
  return await request.post({
    url: '/ict/delivery/second-project-manager-approve',
    data
  })
}

// 审批流程-项目交付-回退到交付经理
export const refuseProjectDeliveryProcess = async (data) => {
  return await request.post({
    url: '/ict/delivery/return',
    data
  })
}

// 审批流程-项目审计-交付经理通过
export const agreeProjectAuditProcess = async (data) => {
  return await request.post({
    url: '/ict/audit/approve',
    data
  })
}

// 审批流程-后评估-通过
export const agreeProjectReviewProcess = async (data) => {
  return await request.post({
    url: '/ict/review/approve',
    data
  })
}

// 获取筛选后的用户列表
export const getProjectUserList = async (params) => {
  return await request.get({
    url: '/ict/get_handler/get',
    params
  })
}

// 获取项目列表分页
export const getAllProjectsPage = async (data) => {
  return await request.post({
    url: '/ict/projectTransfer/search/all-project-page',
    data
  })
}

// 提交项目实施进度周报
export const addWeeklyReports = async (data) => {
  return await request.post({
    url: '/ict/progress/add-progress',
    data
  })
}

// 创建项目变更流程实例
export const createProjectChange = async (data) => {
  return await request.post({
    url: '/ict/change/bpm/create',
    data
  })
}

// 根据projectCode查询全部变更项
export const getAllChangeListByProjectCode = async (params) => {
  return await request.get({
    url: '/ict/change/get',
    params
  })
}

// 根据projectCode和changeKey list查询全部变更流程
export const getAllChangeProcessList = async (data) => {
  return await request.post({
    url: '/ict/change/bpm/get-instance-by-project',
    data
  })
}

//风险清单
// 获得风险项目分页
export const getRiskPage = async (data) => {
  return await request.post({ url: '/ict/risk/page', data })
}

//获取风险项目详情
export const getRiskDetail = async (id) => {
  return await request.get({ url: '/ict/risk/get?id=' + id })
}

//创建风险项目
export const createRisk = async (data) => {
  return await request.post({ url: '/ict/risk/create', data })
}

//更新风险项目
export const updateRisk = async (data) => {
  return await request.put({ url: '/ict/risk/update', data })
}

// 风险数量统计
export const getRiskData = async () => {
  return await request.get({ url: '/ict/risk/risk-num' })
}

//批量删除风险项目
export const deleteRiskList = async (ids) => {
  return await request.delete({
    url: `/ict/risk/delete`,
    params: {
      ids: ids.join(',')
    }
  })
}

//统计分析
// 不同时间的项目数量统计
export const getTimeData = async (params) => {
  return await request.get({ url: '/ict/statistical/statistical-by-time', params })
}

// 不同地市的项目数量统计
export const getRegionData = async () => {
  return await request.get({ url: '/ict/statistical/statistical-by-region' })
}

// 区域不同阶段的项目数量统计
export const getAreaData = async (params) => {
  return await request.get({ url: '/ict/statistical/region-statistical-by-stage', params })
}

// 个人不同阶段的项目数量统计
export const getPersonData = async (params) => {
  return await request.get({ url: '/ict/statistical/person-statistical-by-stage', params })
}

// 指标统计
export const getQuotaData = async (params) => {
  return await request.get({ url: '/ict/statistical/indicator-statistics', params })
}

// 合同汇总
export const getTotalData = async () => {
  return await request.get({ url: '/ict/statistical/project-statistics' })
}

// 项目数量统计
export const getProjectNumber = async () => {
  return await request.get({ url: '/ict/statistical/projectNumber-statistics' })
}

// 知识库上新
export const getKnowledgeNew = async () => {
  return await request.get({ url: '/ict/statistical/knowledge-newArrivals' })
}

// 根据我的权限角色获取我的可选项
export const getRoleSelect = async () => {
  return await request.get({ url: '/ict/statistical/get-region' })
}

// 简要查询
export const getAreaNumber = async (data) => {
  return await request.post({ url: '/ict/statistical/brief-query', data })
}

// 详细查询
export const getAreaDetail = async (data) => {
  return await request.post({ url: '/ict/statistical/detail-query', data })
}

// 项目查询
export const getProjectPanel = async (data) => {
  return await request.post({ url: '/ict/statistical/project-query', data })
}

//案例库
// 获得案例库分页
export const getCasePage = async (data) => {
  return await request.post({ url: '/ict/caseLibrary/page', data })
}

//获取案例库详情
export const getCaseDetail = async (id) => {
  return await request.get({ url: '/ict/caseLibrary/get?id=' + id })
}

//创建案例库
export const createCase = async (data) => {
  return await request.post({ url: '/ict/caseLibrary/create', data })
}

//批量创建案例库
export const createCaseList = async (data) => {
  return await request.post({ url: '/ict/caseLibrary/createBatch', data })
}

//更新案例库
export const updateCase = async (data) => {
  return await request.put({ url: '/ict/caseLibrary/update', data })
}

//项目一键导入案例库
// export const importCase = async (params) => {
//   return await request.get({ url: '/ict/caseLibrary/importCaseLibrary', params })
// }

// 项目一键导入案例库
export const importCase = async (params) => {
  const token = getAccessToken()
  return axios(`${config.base_url}/ict/caseLibrary/importCaseLibrary`, {
    method: 'get',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${token}`
    },
    params
  })
}

//批量删除案例库
export const deleteCaseList = async (ids) => {
  return await request.delete({
    url: `/ict/caseLibrary/delete`,
    params: {
      ids: ids.join(',')
    }
  })
}

//制度库
// 获得制度库分页
export const getFilePage = async (data) => {
  return await request.post({ url: '/ict/institutionLibrary/page', data })
}

//获取制度库详情
export const getFileDetail = async (id) => {
  return await request.get({ url: '/ict/institutionLibrary/get?id=' + id })
}

//创建制度库
export const createFile = async (data) => {
  return await request.post({ url: '/ict/institutionLibrary/create', data })
}

//更新制度库
export const updateFile = async (data) => {
  return await request.put({ url: '/ict/institutionLibrary/update', data })
}

//批量删除制度库
export const deleteFileList = async (ids) => {
  return await request.delete({
    url: `/ict/institutionLibrary/delete`,
    params: {
      ids: ids.join(',')
    }
  })
}

//项目变更
//根据projectCode查询全部变更项
export const getProjectChange = async (params) => {
  return await request.get({ url: '/ict/change/get', params })
}

//查询我的全部变更项
export const getChangePage = async () => {
  return await request.get({ url: '/ict/change/get-all' })
}

//查询我的全部变更项-新
export const getMyChangePage = async (data) => {
  return await request.post({ url: '/ict/change/get-all-new', data })
}

//创建项目变更
export const createChange = async (data) => {
  return await request.post({ url: 'ict/change/add', data })
}

//更新项目变更
export const updateChange = async (data) => {
  return await request.post({ url: '/ict/change/update', data })
}

//删除项目变更
export const deleteChangeList = async (data) => {
  return await request.delete({
    url: `/ict/change/delete`,
    data
  })
}

// 审批流程-项目变更-建设单位部门经理通过
export const agreeProjectChangeDepartmentManagerProcess = async (data) => {
  return await request.post({
    url: '/ict/change/bpm/dept-manager-approve',
    data
  })
}

// 审批流程-项目变更-省端主管通过
export const agreeProjectChangeSupervisorProcess = async (data) => {
  return await request.post({
    url: '/ict/change/bpm/supervisor-approve',
    data
  })
}

// 审批流程-项目变更-不通过
export const refuseProjectChangeProcess = async (data) => {
  return await request.post({
    url: '/ict/change/bpm/reject',
    data
  })
}

// 获取关键人信息
export const getKeyPersons = async (data) => {
  return await request.post({
    url: '/ict/key-person/get',
    data
  })
}


//团队组建-下载团队成员模版
export const downloadTeam = async () => {
  return await request.download({
    url: '/ict/team/get-import-template'
  })
}

//团队组建-批量导入团队成员
export const importTeamList = async (formData) => {
  return await request.upload({
    url: '/ict/team/import',
    data: formData
  })
}

//项目定级-查询二级目录-自主能力分类
export const getAutonomousFirstType = async () => {
  return await request.get({ url: '/ict/grading/search/first' })
}

//项目定级-查询二级目录-自主能力分类
export const getAutonomousSecondClassification = async (selectedTypes) => {
  return await request.get({
    url: '/ict/grading/search/second',
    params: {
      firstLevelCategory: selectedTypes
  } })
}

//项目定级-查询能力
export const getAutonomousAbility = async (selectedTypes) => {
  return await request.get({
    url: '/ict/grading/search/ability',
    params: {
      secondLevelCategory: selectedTypes
  } })
}

// 获取自主能力信息报表
export const getAutonomousAbilityReportForm = async (data) => {
  return await request.post({
    url: '/ict/report/autonomous-type',
    data
  })
}

// 获取项目交底流程报表
export const getTransferProcessReportForm = async (data) => {
  return await request.download({
    url: '/ict/report/transfer',
    params: data
  })
}

// 获取项目售中信息报表
export const getOnSaleInfoReportForm = async (data) => {
  return await request.download({
    url: '/ict/report/info',
    params: data
  })
}

// 获取项目交付流程报表
export const getDeliveryProcessReportForm = async (data) => {
  return await request.download({
    url: '/ict/report/delivery',
    params: data
  })
}